$(function() {
	app = new Vue({
		el : '#app',
		data : {
		},
		methods : {
			add : function() {
				$.ajax({
					type : "POST",
					url : '/manager/discount/addDiscount',
					data : $('#discount-form').serialize(),
					beforeSend : function() {

					},
					complete : function() {

					},
					error : function(request) {
						layer.alert("系统出错");
					},
					success : function(data) {
						if (data.status == 0) {
							refreshParentList();
							layer.alert(data.message, function() {
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						}else{
							layer.alert(data.message);
						}
					}
				});
			},
			getIdFromUrl:function(){
				var addr = location.href;
				var index = addr.lastIndexOf('/') + 1;
				var id = addr.substr(index);
				return id;
			},
			init : function() {
				_self = this;
				$("#discount-form").validate({
					rules : {
						discountIntegral : {
							required : true
						},
						limitIntegral : {
							required : true
						},
						daybegin : {
							required : true
						},
						status : {
							required : true
						},
						dayend: {
							required : true
						}
					},
					onkeyup : false,
					focusCleanup : true,
					success : "valid",
					submitHandler : function(form) {
						_self.add();
					}
				});
			}
		}
	});
	
	app.init();
});


function closeWin() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
function resetForm() {
	$('#discount-form')[0].reset();
}